package com.raycloud.manager.impl;

import com.raycloud.dao.UserDao;
import com.raycloud.dao.UserRelationDao;
import com.raycloud.domain.UserRelation;
import com.raycloud.manager.UserRelationMgr;

public class UserRelationMgrImpl implements UserRelationMgr{
	private UserRelationDao userRelationDao;
	private UserDao userDao;
	
	public void setUserRelationDao(UserRelationDao userRelationDao) {
		this.userRelationDao = userRelationDao;
	}
	
	public void setUserDao(UserDao userDao) {
		this.userDao = userDao;
	}

	public void insertOrUpdateFollowRelations(UserRelation followRelation,
			UserRelation fansRelation) {
		//检查是否已经follow过
		UserRelation dbFollowRelation = userRelationDao.getUserRelation(followRelation.getDbId(), followRelation.getUserId(), followRelation.getFollowId(), followRelation.getType());
		if(dbFollowRelation == null) {
			userRelationDao.insertUserRelation(followRelation);
			userRelationDao.insertUserRelation(fansRelation);
			userDao.updateFieldCount(followRelation.getUserId(), 1, "follow");
			userDao.updateFieldCount(followRelation.getFollowId(), 1, "fans");
		}
	}

	
}
